package cn.com.dcsgo.controller;

import cn.com.dcsgo.model.search.SkuEs;
import cn.com.dcsgo.result.Result;
import cn.com.dcsgo.service.SkuService;
import cn.com.dcsgo.vo.search.SkuEsQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * SearchController
 *
 * @author Dcsgo
 * @since 2025/4/27 12:48
 */
@Api(tags = "搜索")
@RestController
@RequestMapping("/weixin/search")
@RequiredArgsConstructor
public class SearchController {
    private final SkuService skuService;

    @ApiOperation(value = "分页获取sku信息", notes = "根据分类id、仓库id以及非必须的关键字")
    @GetMapping("sku/{page}/{size}")
    public Result<Page<SkuEs>> searchSku(@PathVariable Integer page,
                                         @PathVariable Integer size,
                                         SkuEsQueryVo skuEsQueryVo) {
        // Spring Data 中的分页从1 开始
        Pageable pageParma = PageRequest.of(page - 1, size);
        return Result.ok(skuService.getSkuListByPage(pageParma, skuEsQueryVo));
    }
}
